//给定一个字符串，你需要反转字符串中每个单词的字符顺序，同时仍保留空格和单词的初始顺序。 
//
// 
//
// 示例： 
//
// 输入："Let's take LeetCode contest"
//输出："s'teL ekat edoCteeL tsetnoc"
// 
//
// 
//
// 提示： 
//
// 
// 在字符串中，每个单词由单个空格分隔，并且字符串中不会有任何额外的空格。 
// 
// Related Topics 双指针 字符串 
// 👍 354 👎 0


package leetcode.editor.cn;
public class ReverseWordsInAStringIii{
  public static void main(String[] args) {
       Solution solution = new ReverseWordsInAStringIii().new Solution();
       String s = "Let's take LeetCode contest";
       System.out.println(solution.reverseWords(s));
  }
  //leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public String reverseWords(String s) {
        String result = "";
        String[] strings = s.split(" ");
        for (String sub:strings){
            char[] chars = sub.toCharArray();
            int i=0;
            int j = chars.length-1;
            while (i<j){
                char tmp = chars[i];
                chars[i] = chars[j];
                chars[j] = tmp;
                i++;
                j--;
            }
            result += String.copyValueOf(chars) + " ";
        }
        return result.substring(0, result.length()-1);
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}